<template>
  <el-card shadow="never">
    <!-- 路径导航 -->
    <div slot="header">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: '/home' }">
          <i class="el-icon-house"></i> 首页
        </el-breadcrumb-item>
        <el-breadcrumb-item>数据统计</el-breadcrumb-item>
        <el-breadcrumb-item>数据展示</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <!-- 容器 -->
    <div id="box" style="width:600px;height:340px;border:1px solid #eee;margin:20px;"></div>
  </el-card>
</template>

<script>
// 按需导入
import * as echarts from "echarts";
import lodash from "lodash";
export default {
  data() {
    return {
      options: {
        title: {
          text: "用户来源",
        },
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "cross",
            label: {
              backgroundColor: "#E9EEF3",
            },
          },
        },
        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          containLabel: true,
        },
        xAxis: [
          {
            boundaryGap: false,
          },
        ],
        yAxis: [
          {
            type: "value",
          },
        ],
      },
    };
  },
  async mounted() {
    // 获取数据
    let { data: res } = await this.$axios.get("reports/type/1");
    // 错误处理
    if (res.meta.status !== 200) return this.$message.error(res.meta.msg);
    // 合并数据对象
    const options = lodash.merge(this.options, res.data);
    // 实例化echarts对象
    const myEcharts = echarts.init(document.querySelector("#box"));
    // 挂载配置
    myEcharts.setOption(options);
  },
};
</script>

<style lang="less" scoped>
</style>